<template>
  <div>
    <el-form ref="loginForm" :model="loginForm" label-width="60px" class="login-box">
      <h3 class="login-title">欢迎登录</h3>
      <el-form-item label="账号" prop="uName">
        <el-input type="text" placeholder="请输入账号" v-model="loginForm.uName"/>
      </el-form-item>
      <el-form-item label="密码" prop="uPwd">
        <el-input type="password" placeholder="请输入密码" v-model="loginForm.uPwd"/>
      </el-form-item>
      <el-form-item>
        <el-space wrap :size="60">
          <el-button type="primary" v-on:click="onSubmit()">登录</el-button>
          <el-button type="warning" v-on:click="onReset()">重置</el-button>
        </el-space>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { ElMessage } from 'element-plus'
import axios from "axios";
export default {
  name: 'Test',
  data () {
    return {
      loginBg: "url('https://pic.imgdb.cn/item/64fecd1b661c6c8e5477a1f1.webp')",
      loginForm: {
        uName: '',
        uPwd: ''
      }
    }
  },
  methods: {
    // 登录提交
    onSubmit () {
      console.log(this.loginForm.uName + '--' + this.loginForm.uPwd)
      // this.$store.commit('setUName', this.loginForm.uName)
      if(this.loginForm.uName=='admin' && this.loginForm.uPwd=='!QAZ2wsx'){
        ElMessage({
          showClose: true,
          message: '恭喜你，登录成功',
          type: 'success'
        })
        localStorage.setItem('user', this.loginForm.uName);
        this.$router.push('/home')
      } else {
        ElMessage({
          showClose: false,
          message: '登录失败',
          type: 'error'
        })
      }
    },
    // 重置输入
    onReset () {
      this.loginForm.uName = ''
      this.loginForm.uPwd = ''
    }
  },
  mounted () {
    document.body.style.backgroundSize = '100%'
    document.body.style.backgroundImage = this.loginBg
  },
  beforeUnmount () {
    document.body.style.backgroundImage = ''
  }
}
</script>

<style scoped>
.login-box {
  border: 1px solid #DCDFE6;
  width: 350px;
  margin: 120px auto;
  padding: 35px 35px 15px 35px;
  border-radius: 10px;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  box-shadow: 0px 0 25px black;
  background-color: white;
}
.login-title {
  text-align: center;
  margin: 0 auto 30px auto;
  color: #303133;
}
/deep/ .el-form-item__label {
  font-size: 18px;
  color: black;
}
</style>

